package init

import (
    "flag"
    "git.oschina.net/hfwb/tianqi.git/tq/global"
    "os"
    "log"
    "io/ioutil"
    "gopkg.in/yaml.v2"
    "git.oschina.net/hfwb/tianqi.git/tq/mssql"
    "fmt"
)

func init() {
    log.SetFlags(log.Ldate | log.Lshortfile)
    cf := flag.String("config-file", "../config/config.yml", "config file")
    flag.Parse()
    global.Config.ConfigFile = *cf
    if file, err := os.OpenFile(*cf, os.O_RDONLY, 0444); err != nil {
        log.Fatalln(err)
    } else if b, err := ioutil.ReadAll(file); err != nil {
        log.Fatalln(err)
    } else if err := yaml.Unmarshal(b, &global.Config); err != nil {
        log.Fatalln(err)
    }

    var err error
    if global.MssqlConn, err = mssql.NewConn(global.Config.Mssql); err != nil {
        fmt.Println(*global.Config.Mssql)
        log.Fatalln(err)
    } else {
    }
}
